from pynput.keyboard import Key, Controller
from tkinter import ttk, messagebox
from tkinter import *


class BaseOutput:
    def __init__(self):
        self.stop = False
        self.isEnd = True

    # 键盘输出文字 content 内容
    def keyResultContent(self, content):
        kayCon = Controller()
        kayCon.type(content)
        kayCon.press(Key.enter)
        kayCon.release(Key.enter)

    # 创建公共配置
    def commonConfig(self, root):
        cBox = ttk.LabelFrame(root, text='公共配置')
        cBox.pack()
        dev = IntVar()
        dev.set(2)

        row = 0
        ttk.Label(cBox, text='输出速度(毫秒)').grid(row=row, column=0)
        self.speed = Scale(cBox, from_=100, to=5000, orient=HORIZONTAL)
        self.speed.grid(row=row, column=1)
        self.speed.set(50)

        row += 1
        ttk.Label(cBox, text='测试输出').grid(row=row, column=0)
        Text(cBox, width=20, height=3).grid(row=row, column=1)

        return cBox

    # 提示
    def tips(self, message):
        messagebox.showinfo(title='提示', message=message)

    def get_count(self):
        return int(self.count.get())

    def get_speed(self):
        return int(self.speed.get()) / 1000

    def get_strtemp(self):
        return self.strtemp.get(1.0, END).strip('\n')

    # 执行输出入口
    def runMain(self):
        print('>>> 开始 >>>')
        self.stop = False
        self.isEnd = False
        self.run()
        self.stop = True
        self.isEnd = True
        print('>>> 结束 >>>')

    # abstract 创建配置
    def createConfig(self):
        print('config 子类需实现')
        box = ttk.LabelFrame(self.root, text='配置')
        return box

    # abstract 执行输出
    def run(self):
        print('run 子类需实现')
